package com.harmontronics.hanma.paas.paas.domain.iam.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.harmontronics.hanma.paas.paas.domain.iam.repository.persistence.HmUserReportRepository;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.HmUserReport;
import com.harmontronics.hanma.paas.paas.token.ComposeTokenKit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.harmontronics.hanma.paas.paas.domain.iam.repository.po.HmUserReportPO;

@Service("hmUserReportService")
@DS("#header.App-Unique")
public class HmUserReportService {

    @Autowired
    private HmUserReportRepository hmUserReportRepository;


    @Autowired
    private ComposeTokenKit composeTokenKit;

    public void save(HmUserReport hmUserReport) {
            HmUserReportPO po = BeanUtil.toBean(hmUserReport,HmUserReportPO.class);
            hmUserReportRepository.save(po);
    }

    public void update(HmUserReport hmUserReport) {
            HmUserReportPO po = BeanUtil.toBean(hmUserReport,HmUserReportPO.class);
            hmUserReportRepository.updateById(po);
    }


    public HmUserReport getInfo() {
        Long userId = composeTokenKit.getId();
        QueryWrapper<HmUserReportPO> queryWrapper = new QueryWrapper<HmUserReportPO>()
                .eq("user_id",userId);
        HmUserReportPO pos = hmUserReportRepository.getOne(queryWrapper);
        return BeanUtil.toBean(pos,HmUserReport.class);
    }


}